package cz.muni.fi.hauntedhouses.util;

import cz.muni.fi.hauntedhouses.entity.Ghost;
import cz.muni.fi.hauntedhouses.to.GhostTO;
import java.util.ArrayList;
import java.util.List;

public class GhostUtil {
    
    public static GhostTO entityToTO(Ghost g) {
        if (g == null) {
            return null;
        }
        
        GhostTO ghost = new GhostTO();
        ghost.setId(g.getId());
        ghost.setName(g.getName());
        ghost.setDescription(g.getDescription());
        ghost.setHauntingFrom(g.getHauntingFrom());
        ghost.setHauntingTo(g.getHauntingTo());
        ghost.setPower(g.getPower());
        ghost.setSkill(SkillUtil.toDTO(g.getSkill()));
        ghost.setHouse(HouseUtil.toDTO(g.getHouse()));
        
        return ghost;
    }
    
    public static Ghost TOToEntity(GhostTO g) {
        if (g == null) {
            return null;
        }
        
        Ghost ghost = new Ghost();
        ghost.setId(g.getId());
        ghost.setName(g.getName());
        ghost.setDescription(g.getDescription());
        ghost.setHauntingFrom(g.getHauntingFrom());
        ghost.setHauntingTo(g.getHauntingTo());
        ghost.setPower(g.getPower());
        ghost.setSkill(SkillUtil.toDAO(g.getSkill()));
        ghost.setHouse(HouseUtil.toDAO(g.getHouse()));
        
        return ghost;
    }
    
    public static List<GhostTO> listToTO(List<Ghost> ghosts) {
        List<GhostTO> ghostsTO = new ArrayList<GhostTO>();
        for (Ghost g : ghosts) {
            ghostsTO.add(GhostUtil.entityToTO(g));
        }
        return ghostsTO;
    }
    
}
